package uni.j2ee.forum.request;

import java.util.Date;
import uni.j2ee.forum.helper.CommonHelper;
import uni.j2ee.forum.model.ForumData;
import uni.j2ee.forum.model.ForumPost;
import uni.j2ee.forum.model.ForumUser;

public class AddPostRequest {
	
	final private ForumPost data = new ForumPost();
	private ForumUser user;
	
	public ForumPost getData() {
		return data;
	}

	public String addPost() {        
                data.setUsername(user);
		data.setPostDate(new Date());
		
		if (ForumData.getInstance().addEntity(data)) {
			CommonHelper.addMessage("post_added", false);
		} else {
			CommonHelper.addMessage("post_add_error", true);
		}

		//remove text from input field
		CommonHelper.getRequestMap().remove("addPostRequest");
		return null;
	}

	public void setUser(ForumUser user) {
		this.user = user;
	}

	public ForumUser getUser() {
		return user;
	}

}
